package com.tengju.bff.interfaces.manage.csa;

import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.ManageEntrance;
import com.tengju.user.application.csa.GenSecCustomerServiceService;
import com.tengju.user.application.csa.dto.GenSecCustomerServiceForm;
import com.tengju.user.domain.shared.ResultCodeEnum;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@Api(tags = "俱乐部客服后台管理")
@RequestMapping(value = "manage/club/csa")
@Slf4j
@ManageEntrance
public class GenSecCustomerServiceController {

    @Autowired
    GenSecCustomerServiceService customerServiceService;

    @RequestMapping(value = "/update/customerServiceInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Integer> updateClubCustomerServiceInfo(@RequestBody GenSecCustomerServiceForm genSecCustomerServiceForm) {
        try {
            return ApiResponse.newSuccess(customerServiceService.updateCustomerServiceInfo(genSecCustomerServiceForm));
        } catch (Exception e) {
            log.error("俱乐部:{},客服信息更新失败：", genSecCustomerServiceForm.getSecIdCode(),e);
            return ApiResponse.newFailure(ResultCodeEnum.UPDATE_FAIL.getCode(),ResultCodeEnum.UPDATE_FAIL.getMsg());
        }
    }

    @RequestMapping(value = "/add/customerServiceInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Long> addClubCustomerServiceinfo(@RequestBody GenSecCustomerServiceForm genSecCustomerServiceForm) {
        return ApiResponse.newSuccess(customerServiceService.addCustomerServiceInfo(genSecCustomerServiceForm));
    }

    @GetMapping(value = "/clear/customerServiceInfo", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Boolean> clearClubCustomerServiceinfo(@RequestParam Long secIdCode) {
        try {
            customerServiceService.clearCustomerServiceInfo(secIdCode);
            return ApiResponse.newSuccess(true);
        } catch (Exception e) {
            log.error("俱乐部:{},客服信息删除失败：",secIdCode,e);
            return ApiResponse.newFailure(ResultCodeEnum.DELETE_FAIL.getCode(),ResultCodeEnum.DELETE_FAIL.getMsg());
        }
    }



}
